home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3422 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.5 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Wizard Question
  5. Date: Tue, 23 Jan 1996 22:11:24 GMT
  6. Organization: Netcom
  7. Message-ID: <31055b5f.172082688@nntp.ix.netcom.com>
  8. References: <310533BD.847@jsp.com>
  9. NNTP-Posting-Host: ix-dc18-03.ix.netcom.com
  10. X-NETCOM-Date: Tue Jan 23  2:10:43 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13.  
  14. Jeff PErry <jeff@jsp.com> wrote:
  15.  
  16. > So, you think you're a C++ Wizard, eh?  Good.  Then could you 
  17. > please comment on the following few statements:
  18. >     throw "This is an exception thrown deep in the call stack";
  19. >     ...
  20. >     catch (const char *E)
  21. >     {
  22. >         // Do something with E
  23. >     }
  24. > This is a practice that I have used before, and only recently 
  25. > did it occur to me that it might not be such a great idea to be 
  26. > throwing a pointer to something on the stack.  On the other 
  27. > hand, it is a constant, so it has to live somewhere permanently.
  28. > The question is: Is it safe to assume that the string to which E 
  29. > points will be valid in my catch block, even though the call 
  30. > stack has been unwound?
  31.  
  32. A string literal has static storage duration.  The string literal
  33. remains in existence until the program ends.
  34.  
  35. In any case, you are throwing the exception with an array object and a
  36. copy of the object must be made and preserved until the exception is
  37. handled (unless, of course, the compiler can determine that this is
  38. unnecessary).
  39.  
  40. In short, this is safe.
  41.  
  42. Michael M Rubenstein
  43.